<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>消息列表</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

	
	</head>
<body>
	<input type="checkbox" name="btn" id="btn"/><label for="btn">全选</label><br/>
    <input type="checkbox" name="choose" id="checkbox1"/><label for="checkbox1">选项1</label><br/>
    <input type="checkbox" name="choose" id="checkbox2"/><label for="checkbox2">选项2</label><br/>
    <input type="checkbox" name="choose" id="checkbox3"/><label for="checkbox3">选项3</label><br/>
    <input type="checkbox" name="choose" id="checkbox4"/><label for="checkbox4">选项4</label><br/>
    <input type="checkbox" name="choose" id="checkbox5"/><label for="checkbox5">选项5</label><br/>
    
    <script type="text/javascript">
window.onload = function(){
    var oBtn = document.getElementById('btn');
    var oBtn2 = document.getElementById('btn2');
    var oInput = document.getElementsByName('choose');
    
    for(var i = 0;i < oInput.length; i++){
        oInput[i].onclick = function(){
            this.checked ? allCheck() : oBtn.checked = false;
        };
    };
    
    //全选
    oBtn.onclick = function(){
        for(var i = 0;i < oInput.length; i++){
            oBtn.checked ? oInput[i].checked = true : oInput[i].checked = false;
        };
    };
    
    //反选
    oBtn2.onclick = function(){
        for(var i = 0;i < oInput.length; i++){
            oInput[i].checked = !oInput[i].checked;
        };
        allCheck();
    };
};

//判断是否全选
function allCheck(){
    var oBtn = document.getElementById('btn');
    var oInput = document.getElementsByName('choose');
    var allCheck = true;
    for(var i = 0;i < oInput.length; i++){
        if(!(oInput[i].checked)) allCheck = false;
    };
    allCheck ? oBtn.checked = true : oBtn.checked = false;
};
</script>
</body>

</html>